const http=require('http')
const server=http.createServer()
const path=require('path')
const fs=require('fs')
const url=require('url')
// const queryString=require('queryString')
const webroot=path.join(__dirname,'src')
const nofont=path.join(webroot,'nofont.html')
server.on('request',(req,res)=>{
    let uri=req.url  //请求地址
    let {pathname,query}=url.parse(uri,true)
    pathname=pathname=='/'?'/index.html':pathname
    if('favicon.ico'!=pathname){
        let filepath=path.join(webroot,pathname)
        fs.readFile(filepath,"utf-8",(err,data)=>{
            if(err){
                res.end(fs.readFileSync(nofont))
            }else{
                res.end(data)
            }
        })
    }
})
server.listen(8090,()=>{
    console.log('is ok server')
})